Skip to content

Fix for Array index out of bounds#809

Merged
Andrey1994 merged 1 commit intomasterfrom
finding-autofix-33882778
Apr 26, 2026
Merged

Fix for Array index out of bounds#809
Andrey1994 merged 1 commit intomasterfrom
finding-autofix-33882778

Conversation

@Andrey1994
Copy link
Copy Markdown
Member

General fix: only read args[i + 1] when it exists. For options that require a value, guard with i + 1 < args.length; if missing, fail fast with a clear exception.

Best fix in this file: in parse_args (lines ~36–106), add a single guard at the top of the loop to validate value-bearing flags before any branch accesses args[i + 1]. This avoids repetitive checks and preserves existing behavior for valid inputs. Then keep the existing assignments/parsing logic unchanged.

Concretely:

  • File: java_package/brainflow/src/main/java/brainflow/examples/BrainFlowGetData.java
  • Region: inside parse_args, immediately inside the for loop and before first if (args[i].equals(...)).
  • Add:
    • String arg = args[i];
    • a combined condition checking whether arg is one of the value-requiring flags and i + 1 >= args.length
    • throw IllegalArgumentException with a helpful message.
  • Optionally use arg in existing if statements for readability (no functional change).

No new imports or dependencies are required.

Suggested fixes powered by Copilot Autofix. Review carefully before merging.

Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com>
@Andrey1994 Andrey1994 marked this pull request as ready for review April 26, 2026 15:39
@Andrey1994 Andrey1994 merged commit fc69852 into master Apr 26, 2026
38 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant